# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: acxz <akashpatel2008 at yahoo dot com>
# Contributor: Tim Rakowski <tim.rakowski@gmail.com>
# Contributor: Javier Fuentes <0xffaa.rm@gmail.com>
# Contributor: Figo.zhang <figo1802@gmail.com>
# Contributor: hauptmech

pkgname=flann
pkgver=1.9.2
pkgrel=3
pkgdesc="A library for performing fast approximate nearest neighbor searches in high dimensional spaces"
arch=('loong64' 'x86_64')
url='https://github.com/flann-lib/flann'
license=('BSD')
depends=('lz4' 'hdf5')
makedepends=('cmake' 'python' 'texlive-core' 'ninja')
optdepends=('python: python bindings'
            'cuda: cuda support')
source=("$pkgname-$pkgver.tar.gz::https://github.com/mariusmuja/flann/archive/${pkgver}.tar.gz")
sha512sums=('e1235383e4e3919607cd1417738220c1601342dcf908071a6f75039c45116bd558d9f0534be037b1a8ac5b4ba5b0be5b62bf1d96e44911f14b34f73d941addb2')

prepare() {
  cd "$srcdir/flann-${pkgver}"

  sed -i "s|setup\.py install|setup.py install --root=$pkgdir --optimize=1|" src/python/CMakeLists.txt
}

build() {
  cd "$srcdir/flann-${pkgver}"

  export CXXFLAGS+=" -ffat-lto-objects"
  cmake \
      -Bbuild \
      -GNinja \
      -DCMAKE_BUILD_TYPE=None \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DBUILD_MATLAB_BINDINGS=OFF \
      -DBUILD_PYTHON_BINDINGS=ON \
      -DPYTHON_EXECUTABLE=/usr/bin/python \
      -DBUILD_TESTS=OFF \
      -DBUILD_EXAMPLES=OFF
  ninja -C build
  ninja -C build doc
}

package() {
  cd "$srcdir/flann-${pkgver}"

  DESTDIR="$pkgdir" ninja -C build install

  install -D -m644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
